import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.Random;

import javax.swing.JPanel;
import javax.swing.Timer;


public class TestPanel extends JPanel
{
	
	private Timer timer;
	private int radius = 0;
	private Random random = new Random();
	
	private boolean isGoingForward = true;
	private Point mouseLocation = new Point();
	
	public TestPanel() {
		this.timer = new Timer(10, new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(isGoingForward && radius < 100)
					radius++;
				else
					isGoingForward = false;
				
				if(!isGoingForward && radius > 0)
					radius--;
				else
					isGoingForward = true;
					
				TestPanel.this.repaint();
//				System.out.println(radius);
			}});
		this.timer.start();
		
		this.setBackground(Color.ORANGE);
		
		this.addMouseMotionListener(new MouseMotionListener(){

			@Override
			public void mouseDragged(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseMoved(MouseEvent e) {
				mouseLocation = new Point(e.getX(), e.getY());
			}
			
		});
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		
		super.paintComponent(g);

		Graphics2D g2d = (Graphics2D)g.create();
		
		for (int i = 0; i < 50; i++) {
			g2d.setColor(Color.RED);
			g2d.setStroke(new BasicStroke(1));
			g2d.fillOval(random.nextInt(this.getWidth()), random.nextInt(this.getHeight()), 2*radius, 2*radius);
		}
		
//		g2d.drawLine(0, 0, 100, 100);
	}
}
